package Hgw;

import java.util.Scanner;

public class Hgw01 {
	static String users[][] = new String[100][4];
	static String press[][] = new String[100][5];
	static String pressinfo[][] = new String[100][3];
	static Scanner scan = new Scanner(System.in);
	static String name;
	
	public static void main(String[] args) {
		tian1();
		tian2();
		tian3();
	 System.out.println("欢迎来到图书管理器");
	 System.out.println("1.登入2.注册");
	 int key = scan.nextInt();
	 
	 switch (key) {
	case 1:
			deng();
		break;
    case 2:
    		zhu();
		    deng();
		break;
	default:
		System.out.println("您输入有误,退出系统！");
		break;
	}
}
	private static void zhu() {
		int ji = -1;
		for (int i = 0; i < users.length; i++) {
			if (users[i][1]==null) {
				ji = i;
				break;
			}
		}
			System.out.println("请输入部门");
			users[ji][0]=scan.next();
			System.out.println("请输入用户名");
			users[ji][1]=scan.next();
			System.out.println("请输入用户密码");
			users[ji][2]=scan.next();
			System.out.println("请输入用户类型");
			users[ji][3]=scan.next();	
		    System.out.println("注册成功！");
		
	}
	private static void deng() {
		for (int i = 0; i < 3; i++) {
			String yname;
			String ypass;
			System.out.println("请输入用户名");
			yname = scan.next();
			System.out.println("请输入用户密码");
			ypass = scan.next();
			boolean ce = ce(yname,ypass);
			if (ce) {
				System.out.println("登入成功！");
				
				break;
			}else {
			    System.out.println("该用户不存在或者密码错误！请重新登录！");
			}
		}
		
		
	}
	private static boolean ce(String yname,String ypass) {
		boolean flag = false;
		for (int i = 0; i < users.length; i++) {
			if (yname.equals(users[i][1]) && ypass.equals(users[i][2])) {
				flag = true;
			}
		}
		return flag;
		
	}
	public static void tian1() {
		users[0][0] = "软件部";
		users[0][1] = "abc";
		users[0][2] = "123";
		users[0][3] = "管理员";
		
		users[1][0] = "小卖部";
		users[1][1] = "xiao";
		users[1][2] = "123";
		users[1][3] = "普通用户";
	}
	public static void tian2() {
		press[0][0] = "1";
		press[0][1] = "西游记";
		press[0][2] = "39.99";
		press[0][3] = "人民出版社";
		press[0][4] = "吴承恩";
		
		press[1][0] = "2";
		press[1][1] = "水浒传";
		press[1][2] = "38.99";
		press[1][3] = "人民出版社";
		press[1][4] = "施耐庵";
	}
	public static void tian3() {
		pressinfo[0][0] = "人民出版社";
		pressinfo[0][1] = "中国北京";
		pressinfo[0][2] = "张三";
		
		pressinfo[1][0] = "闽大出版社";
		pressinfo[1][1] = "中国福建";
		pressinfo[1][2] = "李四";
	}
}
package Dj;

import java.util.Scanner;

public class Dj01 {
	static String users	   [][] = new String[100][4];
	static String press    [][] = new String[100][5];
	static String pressinfo[][] = new String[100][3];
	static Scanner scan = new Scanner(System.in);
	static String name;
	
	public static void main(String[] args) {
		tian1();
		tian2();
		tian3();
		top();
}
	private static void top() {
		while (true) {
		
	 System.out.println("欢迎来到图书管理系统！");
	 System.out.println("1.登入2.注册");
	 int key = scan.nextInt();
	 
	 switch (key) {
	case 1:
			deng();
		break;
    case 2:
    		zhu();
		    deng();
		break;
	default:
		System.out.println("您输入有误,退出系统！");
		break;
	}
		}
		
	}
	private static void zhu() {
		int ji = -1;
		for (int i = 0; i < users.length; i++) {
			if (users[i][1]==null) {
				ji = i;
				break;
			}
		}
			System.out.println("请输入部门");
			users[ji][0]=scan.next();
			System.out.println("请输入用户名");
			users[ji][1]=scan.next();
			System.out.println("请输入用户密码");
			users[ji][2]=scan.next();
			System.out.println("请输入用户类型");
			users[ji][3]=scan.next();	
		    System.out.println("注册成功！");
		
	}
	private static void deng() {
		for (int i = 0; i < 3; i++) {
			String yname;
			String ypass;
			System.out.println("请输入用户名");
			yname = scan.next();
			name = yname;
			System.out.println("请输入用户密码");
			ypass = scan.next();
			boolean ce = ce(yname,ypass);
			if (ce) {
				System.out.println("登入成功！");
				guan();
				break;
			}else {
			    System.out.println("该用户不存在或者密码错误！请重新登录！");
			}
		}
		
		
	}
	private static void guan() {
		System.out.println(name+"欢迎您使用闽大书籍管理系统！！！");
		System.out.println("请输入数字进行选择：1.图书管理  2.出版社管理  3.退出登录  4.退出系统");
		int k=scan.nextInt();
		switch (k) {
		case 1:
			tu();
			break;
		case 2:
			cbs();
			break;
		case 3:
			System.exit(0);
			break;
		case 4:
			deng();
			break;

		default:
			break;
		}
		
	}
	private static void cbs() {
		while (true) {
			System.out.println("请输入：1.增加 2.删除 3.更新 4.根据出版社名称查询 5.查询所有出版社 6.返回上一级菜单");
			int key = scan.nextInt();
			switch (key) {
			case 1:
				z2();
				break;
			case 2:
				s2();
				break;
			case 3:
				g2();
				break;
			case 4:
				c21();
				break;
			case 5:
				c22();
				break;
			case 6:
				guan();
				break;

			default:
				break;
			}
		}
	}
	private static void c22() {
		int ji = -1;
		for (int i = 0; i < pressinfo.length; i++) {
			if (pressinfo[i][1]==null) {
				ji = i;
				break;
			}
		}
		System.out.println("出版社名称\t地址\t联系人");
		for (int i = 0; i < ji; i++) {
			System.out.print(pressinfo[i][0]+"\t");
			System.out.print(pressinfo[i][1]+"\t");
			System.out.print(pressinfo[i][2]);
			System.out.println();
		}
		
	}
	private static void c21() {
		System.out.println("请输入出版社名称：");
		String cbsname = scan.next();
		int ce = cbsce(cbsname);
		if (ce!=-1) {
			System.out.println("出版社名称："+pressinfo[ce][0]);
			System.out.println("出版社地址："+pressinfo[ce][1]);
			System.out.println("出版社联系人："+pressinfo[ce][2]);
		}else {
			cbs();
		}
		
	}

	private static void g2() {
		System.out.println("请输入要更新的出版社名称：");
		String isbncbs = scan.next();
		int isbn = cbsce(isbncbs);
		if(isbn!=-1){
		System.out.println("出版社名称"+"\t"+"地址"+"\t"+"联系人");
		System.out.println(pressinfo[isbn][0]+"\t"+pressinfo[isbn][1]+"\t"+pressinfo[isbn][2]);
				System.out.println("请输入要更新的地址：");
				pressinfo[isbn][1]=scan.next();
				System.out.println("请输入要更新的联系人姓名：");
				pressinfo[isbn][2]=scan.next();
				System.out.println("更新成功！！！");
				System.out.println("出版社名称"+"\t"+"地址"+"\t"+"联系人");
				System.out.println(pressinfo[isbn][0]+"\t"+pressinfo[isbn][1]+"\t"+pressinfo[isbn][2]);
			}else {
				cbs();
			}
		
	}

	private static void s2() {
		System.out.println("请输入要删除的出版社名称：");
		String cbsshu = scan.next();
		int isbn= cbsce(cbsshu);
		if(isbn!=-1){
		for (int i = 0; i < pressinfo[0].length; i++) {
			pressinfo[isbn][i]=null;
			System.out.println("删除成功");
			cbs();
			break;
		}
		}else {
			cbs();
		}
		
	}
	private static int cbsce(String cbs) {
		int ce = -1;
		boolean flag = false;
		for (int i = 0; i < pressinfo.length; i++) {
			if (cbs.equals(pressinfo[i][0])) {
				ce = i;
				flag = true;
				break;
			}
		}
		if (flag==false) {
			System.out.println("该出版社不存在");
		}
		return ce;
	}
	private static void z2() {
		int ji = -1;
		for (int i = 0; i < pressinfo.length; i++) {
			if (pressinfo[i][1]==null) {
				ji = i;
				break;
			}
		}
		System.out.println("请输入出版社名称：");
		pressinfo[ji][0]=scan.next();
		System.out.println("请输入出版社地址：");
		pressinfo[ji][1]=scan.next();
		System.out.println("请输入出版社联系人：");
		pressinfo[ji][2]=scan.next();
	    System.out.println("出版社添加成功");
		cbs();
	}
	
	private static void tu() {
		while (true) {
			System.out.println("请输入：1.增加 2.删除 3.更新 4.查询 5.返回上一级菜单");
			int key = scan.nextInt();
			switch (key) {
			case 1:
				z1();
				break;
			case 2:
				s1();
				break;
			case 3:
				g1();
				break;
			case 4:
				c1();
				break;
			case 5:
				guan();
				break;

			default:
				break;
			}
			
		}
		
		
	}
	private static void c1() {
		while (true) {
			System.out.println("请输入查询种类：1.isbn 2.书名（模糊） 3.出版社 4. 作者 5. 价格范围 6.查询所有 7.返回上一级");
			int key = scan.nextInt();
			switch (key) {
			case 1:
				System.out.println("请输入ISBN号：");
				String isbn = scan.next();
				int ce = tuce(isbn);
				if (ce!=-1) {
					System.out.println("ISBN\t书名\t价格\t出版社\t作者");
					System.out.println(press[ce][0]+"\t"+press[ce][1]+"\t"+press[ce][2]+"\t"+press[ce][3]+"\t"+press[ce][4]);
				}else {
					c1();
				}				
				break;
			case 2:
				System.out.println("请输入书名（模糊）：");
				String tuname = scan.next();
				System.out.println("ISBN\t书名\t价格\t出版社\t作者");
				for (int i = 0; i < press.length; i++) {
					if (press[i][1]!=null) {
						if (press[i][1].indexOf(tuname)!=-1) {
						System.out.println(press[i][0]+"\t"+press[i][1]+"\t"+press[i][2]+"\t"+press[i][3]+"\t"+press[i][4]);
						}
					}
					
				}
				break;
			case 3:
				int ji[] = new int[100];
				for (int i = 0; i < pressinfo.length; i++) {
					if (pressinfo[i][1]!=null) {
						ji[i] = i;
					}
				}
				int q = -1;
				for (int i = 0; i < ji.length; i++) {
					if (pressinfo[i][1]==null) {
						q = i;
						break;
					}
				}
				System.out.print("请输入出版社前的数字进行选择：");
				for (int i = 0; i < q; i++) {
					int ab = ji[i];
					System.out.print(i+"."+pressinfo[ab][0]);
				}
					System.out.println();
					int k =scan.nextInt();
					k(k);
						break;
			case 4:
				int w = 0;
				System.out.println("请输入作者姓名：");
				String zname = scan.next();
				System.out.println("ISBN\t书名\t价格\t出版社\t作者");
				for (int i = 0; i < press.length; i++) {
					if (zname.equals(press[i][4])) {
						System.out.println(press[i][0]+"\t"+press[i][1]+"\t"+press[i][2]+"\t"+press[i][3]+"\t"+press[i][4]);
						w = 1;
					}
				}
				if (w==0) {
					System.out.println("没有该作者");
				}
				break;
			case 5:
				int a2[] =new int[100];
				int b = 0; 
				for (int i = 0; i <press.length ; i++) {
					if (press[i][2]!=null) {
						a2[i] = Integer.parseInt(press[i][2]);
					}
				}
				System.out.println("请输入最低价格");
				int min = scan.nextInt();
				System.out.println("请输入最高价格");
				int max = scan.nextInt();
				System.out.println("ISBN\t书名\t价格\t出版社\t作者");
				for (int i = 0; i < press.length; i++) {
					if (min<a2[i] && a2[i]<max) {
					    System.out.println(press[i][0]+"\t"+press[i][1]+"\t"+press[i][2]+"\t"+press[i][3]+"\t"+press[i][4]);
					    b = 1;
					}
				}
				if (b==0) {
					System.out.println("没有该书");
				}
				break;
			case 6:
				int ji11 = -1;
				for (int i = 0; i < press.length; i++) {
					if (press[i][1]==null) {
						ji11 = i;
						break;
					}
				}
				System.out.println("ISBN\t书名\t价格\t出版社\t作者");
				for (int i = 0; i < ji11; i++) {
					System.out.print(press[i][0]+"\t");
					System.out.print(press[i][1]+"\t");
					System.out.print(press[i][2]+"\t");
					System.out.print(press[i][3]+"\t");
					System.out.print(press[i][4]+"\t");
					System.out.println();
				}
				break;
			case 7:
				tu();
				break;

			default:
				break;
			}
		}
	}
	
	private static void k(int k) {
		switch (k) {
		case 0:
			System.out.println("ISBN\t书名\t价格\t出版社\t作者");
			for (int i = 0; i < press.length; i++) {
				if (pressinfo[0][0].equals(press[i][3])) {
					System.out.println(press[i][0]+"\t"+press[i][1]+"\t"+press[i][2]+"\t"+press[i][3]+"\t"+press[i][4]);
				}
			}
			
			break;
		case 1:
			System.out.println("ISBN\t书名\t价格\t出版社\t作者");
			for (int i = 0; i < press.length; i++) {
				if (pressinfo[1][0].equals(press[i][3])) {
				System.out.println(press[i][0]+"\t"+press[i][1]+"\t"+press[i][2]+"\t"+press[i][3]+"\t"+press[i][4]);
			}
		}
			
		break;
		
		default:
			break;
		}
		
	}
	private static void g1() {
		System.out.println("请输入ISBN号：");
		String isbnshu = scan.next();
		int isbn = tuce(isbnshu);
		if(isbn!=-1){
				System.out.println("请输入新的书名：");
				press[isbn][1]=scan.next();
				System.out.println("请输入新的价格：");
				press[isbn][2]=scan.next();
				System.out.println("请输入新的出版社：");
				press[isbn][3]=scan.next();
				System.out.println("请输入新的作者：");
				press[isbn][4]=scan.next();
				System.out.println("更新成功！！！");
			}else {
				tu();
			}
		
	}

	private static void s1() {
		System.out.println("请输入要删除的书本名称：");
		String shu = scan.next();
		int ce = -1;
		boolean flag = false;
		for (int i = 0; i < press.length; i++) {
			if (shu.equals(press[i][1])) {
				ce = i;
				flag = true;
				break;
			}
		}
			if (flag==false) {
				System.out.println("没有找到该书！");
				System.out.println("删除失败");
			}
		if(ce!=-1){
		for (int i = 0; i < press[0].length; i++) {
			press[ce][i]=null;
			System.out.println("删除成功");
			break;
		}
		}else {
			tu();
		}
	}
	private static void z1() {
		int ji = -1;
		for (int i = 0; i < press.length; i++) {
			if (press[i][1]==null) {
				ji = i;
				break;
			}
		}
		System.out.println("请输入图书ISBN：");
		press[ji][0]=scan.next();
		System.out.println("请输入书名：");
		press[ji][1]=scan.next();
		System.out.println("请输入价格：");
		press[ji][2]=scan.next();
		System.out.println("请输入出版社：");
		press[ji][3]=scan.next();	
	    System.out.println("请输入作者：");
	    press[ji][4]=scan.next();
	    System.out.println("添加成功！！！");
		
	}
	private static int tuce(String shu) {
		int ce = -1;
		boolean flag = false;
		for (int i = 0; i < press.length; i++) {
			if (shu.equals(press[i][0])) {
				ce = i;
				flag = true;
				break;
			}
		}
			if (flag==false) {
				System.out.println("没有找到该书！");
				System.out.println("删除失败");
			}	
		return ce;
		}
		
	private static boolean ce(String yname,String ypass) {
		boolean flag = false;
		for (int i = 0; i < users.length; i++) {
			if (yname.equals(users[i][1]) && ypass.equals(users[i][2])) {
				flag = true;
				break;
			}
		}
		return flag;
	}
	public static void tian1() {
		users[0][0] = "软件部";
		users[0][1] = "abc";
		users[0][2] = "123";
		users[0][3] = "管理员";
		
		users[1][0] = "小卖部";
		users[1][1] = "123";
		users[1][2] = "123";
		users[1][3] = "普通用户";
	}
	public static void tian2() {
		press[0][0] = "01";
		press[0][1] = "西游记";
		press[0][2] = "120";
		press[0][3] = "人民出版社";
		press[0][4] = "吴承恩";
		
		press[1][0] = "02";
		press[1][1] = "水浒传";
		press[1][2] = "138";
		press[1][3] = "人民出版社";
		press[1][4] = "施耐庵";
		
		press[2][0] = "03";
		press[2][1] = "西厢记";
		press[2][2] = "89";
		press[2][3] = "闽大出版社";
		press[2][4] = "吴承恩";
	}
	public static void tian3() {
		pressinfo[0][0] = "人民出版社";
		pressinfo[0][1] = "中国北京";
		pressinfo[0][2] = "张三";
		
		pressinfo[1][0] = "闽大出版社";
		pressinfo[1][1] = "中国福建";
		pressinfo[1][2] = "李四";
	}
}